<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>审核</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <script src="../../res/js/jquery-3.1.1.min.js" type="text/javascript" charset="utf-8"></script>
    <link rel="stylesheet" href="../../res/layuis/dist/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <script src="../../res/layuis/dist/layui.js" charset="utf-8"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
    <script src="../../res/js/login_common.js" charset="UTF-8"></script>
</head>
<body>

<form class="layui-form" action="" lay-filter="example" id="attachmentAudit">
    <div class="layui-form-item layui-hide">
        <label class="layui-form-label">附件表id</label>
        <input class="layui-input-block">
        <input type="text" name="auditAttachId" id="auditAttachId"  class="layui-input" style="width: 280px">
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">审核意见</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入意见" lay-verify="content|required" class="layui-textarea" name="auditOpinion" ></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">审核状态</label>
        <div class="layui-input-block">
            <input type="radio" name="auditState" value="10" title="通过">
            <input type="radio" name="auditState" value="20" title="待审核" >
            <input type="radio" name="auditState" value="25" title="未通过" >
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn layui-btn-normal" id="LAY-component-form-getval">提交</button>
        </div>
    </div>
</form>


<script>

    layui.config({
        version: '1572350921010' //为了更新 js 缓存，可忽略
    });
    var ajaxLoading = 0;
    layui.use(['form', 'layedit', 'laydate', 'upload', 'tree', 'util'], function() {
        var form = layui.form
            ,$ = layui.jquery
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , upload = layui.upload
            , tree = layui.tree
            , util = layui.util;

        //表单提交
        layui.$('#LAY-component-form-getval').on('click', function () {
            var formData = new FormData(document.getElementById("attachmentAudit"));
            var data = form.val('example');
            var auditOpinion = data.auditOpinion;
            var auditState = data.auditState;
            var attachId = data.auditAttachId;
            var userId = window.loginObj.manager.usId;
            var userName = window.loginObj.manager.usName;
            console.log("================审核意见的附件表id"+attachId);
            console.log("================审核意见内容"+auditOpinion);
            console.log("================审核意见的状态"+auditState);
            formData.append("creater", userName);
            if (auditOpinion === "" || auditOpinion === null || auditOpinion === undefined){
                ajaxLoading = 2;
                layer.confirm('意见内容不能为空', function(index){
                    layer.close(index);
                });
            }else if (auditState === "" || auditState === null || auditState === undefined){
                ajaxLoading = 2;
                layer.confirm('请选择审核状态', function(index){
                    layer.close(index);
                });
            }else {

            }
            if (ajaxLoading === 0) {
                ajaxLoading = 1;
                $.ajax({
                    url: '../../attachment/insertAudit', //数据接口
                    data: formData,
                    type: "POST",
                    dataType: 'json',
                    processData: false,
                    contentType: false,
                    success: function (data) {

                        if(data.auditMessage > 0){
                            layer.msg('审核成功',{
                                icon: 1,
                                time: 1000,
                                end: function () {
                                    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                                    parent.layer.close(index);
                                    parent.layui.table.reload("demo");
                                }
                            });
                        } else {
                            layer.confirm('审核失败', function(index){
                                layer.close(index);
                            });

                        }


                    }
                });
            }else if (ajaxLoading === 1 || ajaxLoading === 3){
                layer.msg('玩命加载中',{
                    icon: 1,
                    time: 2000,
                    end: function () {

                    }
                });
            }else if (ajaxLoading === 1){
                layer.msg('玩命更新中',{
                    icon: 1,
                    time: 2000,
                    end: function () {

                    }
                });
            }else if (ajaxLoading === 2){
                ajaxLoading = 0;
            }



        });



    });

    //起始赋值事件
    function begins() {
        var form = layui.form
            ,$ = layui.jquery
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , tree = layui.tree
            , util = layui.util;
        var url = "../../attachment/selectStateByAttachId";
        var auditAttachId = $("#auditAttachId").val();

        var data = {
            auditAttachId:auditAttachId
        };
        $.post(url, data, function (obj) {
            form.val('example', {
                "auditState": obj.attachment.auditState//文件状态

            });

        });
    }

</script>
</body>
</html>